<?php
/**
 * TomatoCMS
 *
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 *
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: send.phtml 3930 2010-07-24 17:12:20Z huuphuoc $
 * @since		2.0.6
 */
?>
<?php
$this->headTitle($this->translator('mail_send_page_title'));
?>
<div id="r-heading">
    <img src="<?php echo $this->APP_STATIC_SERVER . '/skins/admin/default/images/mail-48x48.png'; ?>" alt=""/>
    <span><?php echo $this->translate('mail_send_page_title'); ?></span>
</div>

<?php
//nếu có message thì hiển thị
if(!empty($this->message)){
	echo '<div id="message">'.$this->message.'</div>';
}
?>

<form method="post" action="<?php if ($this->currentTemplate) : ?><?php echo $this->url(array('template_id' => $this->currentTemplate->id), 'mail_mail_send_template'); ?><?php else : ?><?php echo $this->url(array(), 'mail_mail_send'); ?><?php endif; ?>" id="sendMailForm">
<div class="grid_12 t_a_bottom"><?php echo $this->translator('mail_send_guide'); ?></div>

<div class="grid_12 t_a_bottom">
	<div class="prefix_1 suffix_1">
		<?php if ($this->templates) : ?>
		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('mail_template'); ?>:</label>
			<select name="template" id="template">
				<option value="">---</option>
				<?php foreach ($this->templates as $template) : ?>
				<option value="<?php echo $template->template_id; ?>"<?php if ($this->currentTemplate && $this->currentTemplate->template_id == $template->template_id) : ?> selected="selected"<?php endif; ?>><?php echo $template->title; ?></option>
				<?php endforeach; ?>
			</select>
		</div>

		<hr />
		<?php endif; ?>

		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('mail_subject'); ?>:</label>
			<input type="text" id="subject" name="subject" style="width: 400px"<?php if ($this->currentTemplate) : ?> value="<?php echo $this->currentTemplate->subject; ?>"<?php endif; ?> />
		</div>

		<hr />

		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('mail_content'); ?>:</label>
			<textarea style="width: 400px; height: 300px" id="content" name="content"><?php if ($this->currentTemplate) : ?><?php echo $this->currentTemplate->body; ?><?php endif; ?></textarea>
		</div>

		<hr />

		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('mail_from_name'); ?>:</label>
			<input type="text" id="fromName" name="fromName" style="width: 200px" value="<?php if ($this->currentTemplate) : ?><?php echo $this->currentTemplate->from_name; ?><?php else : ?><?php echo $this->name; ?><?php endif; ?>" />
		</div>

		<hr />

		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('mail_from_mail'); ?>:</label>
			<input type="text" id="fromMail" name="fromMail" style="width: 200px" value="<?php if ($this->currentTemplate) : ?><?php echo $this->currentTemplate->from_mail; ?><?php else : ?><?php echo $this->email; ?><?php endif; ?>" />
		</div>

		<hr />

		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('mail_reply_to_name'); ?>:</label>
			<input type="text" id="replyToName" name="replyToName" style="width: 200px" value="<?php if ($this->currentTemplate) : ?><?php echo $this->currentTemplate->reply_to_name; ?><?php else : ?><?php echo $this->name; ?><?php endif; ?>" />
		</div>

		<hr />

		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('mail_reply_to_mail'); ?>:</label>
			<input type="text" id="replyToMail" name="replyToMail" style="width: 200px" value="<?php if ($this->currentTemplate) : ?><?php echo $this->currentTemplate->reply_to_mail; ?><?php else : ?><?php echo $this->email; ?><?php endif; ?>" />
		</div>

		<hr />

		<?php if ($this->roles) : ?>
		<div class="clearfix t_a_bottom">
			<label><?php echo $this->translator('mail_send_to'); ?>:</label>
			<select name="role" style="width: 300px">
				<option value=""><?php echo $this->translator('mail_send_to_all'); ?></option>
				<?php foreach ($this->roles as $role) : ?>
				<option value="<?php echo $role->id; ?>"><?php echo $role->description; ?></option>
				<?php endforeach; ?>
			</select>
		</div>

		<hr />
		<?php endif; ?>

		<div class="clearfix t_a_bottom">
			<label>&nbsp;</label>
			<button type="submit"><span><?php echo $this->translator('mail_send_button'); ?></span></button>
		</div>
	</div>
</div>
</form>

<script type="text/javascript">
$(document).ready(function() {
	<?php if ($this->templates) : ?>
	$('#template').change(function() {
		window.location = rtrim('<?php echo $this->url(array(), 'mail_mail_send'); ?>', '/') + '/' + $(this).val();
	});
	<?php endif; ?>
});
</script>